home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / ex / ex8-14.c < prev    next >
C/C++ Source or Header  |  1990-05-29  |  2KB  |  60 lines

  1. // ex8-14.c -- A Dictionary of Patient records keyed by name
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-14.c,v 3.0 90/05/29 14:34:19 kgorlen Rel $
  4.  
  5. #include "Assoc.h"
  6. #include "Dictionary.h"
  7. #include "Iterator.h"
  8. #include "SortedCltn.h"
  9. #include "String.h"
  10. #include "Patient.h"
  11.  
  12. main()
  13. {
  14. // Associate key names with Patient records in a Dictionary
  15.     Dictionary dict;
  16.     cout << "Order of Insertion:" << endl;
  17.  
  18.     String& fried = *new String("Fried Harry I.");
  19.     Patient& patient_fried =
  20.         *new Patient(fried,"987-65-4321",22221);
  21.     dict.addAssoc(fried,patient_fried);
  22.     cout << patient_fried << endl;
  23.  
  24.     String& smith = *new String("Smith John A.");
  25.     Patient& patient_smith =
  26.         *new Patient(smith,"333-22-1111",22223);
  27.     dict.addAssoc(smith,patient_smith);
  28.     cout << patient_smith << endl;
  29.  
  30.     String& chavez = *new String("Chavez Maria G.");
  31.     Patient& patient_chavez =
  32.         *new Patient(chavez,"444-555-6666",22223);
  33.     dict.addAssoc(chavez,patient_chavez);
  34.     cout << patient_chavez << endl;
  35.     cout << endl;
  36.  
  37. // Get sorted list of key Strings
  38.     SortedCltn scltn;
  39.     dict.addKeysTo(scltn);
  40.     
  41. // Print Patient records in sorted order
  42.     cout << "Sorted by Name:" << endl;
  43.     Iterator its(scltn);
  44.     while (its++) {
  45.         cout << *dict.atKey(*its()) << endl;
  46.     }
  47.     cout << endl;
  48.  
  49. // Process queries
  50.     String name;
  51.     while (YES) {
  52.         cout << "Patient name: "; cin >> name;
  53.         if (cin.eof()) break;
  54.         LookupKey* lk = dict.assocAt(name);
  55.         if (lk) cout << *lk->value() << endl;
  56.         else cout << name << " not found" << endl;
  57.     }
  58.     cout << endl;
  59. }
  60.